<?php
class tvapi extends tvapi_default
{
    /**
     * @var settings
     */
    private $settings;

    public function __construct($apiKey = null, $language = 'en')
    {
        if ($apiKey == null) {
            global $settings;
            $this->registerSettings($settings);
            $apiKey = $settings->data['api_key'];
        }
        parent::__construct($apiKey, $language);
    }

    public function registerSettings(settings $settings)
    {
        $this->settings = $settings;
    }

    public function loadMirrors($andPick = true, $forceLoad = false)
    {
        if (empty($this->settings->data['apimirror_xml']) || $forceLoad) {
            $mirrors = parent::loadMirrors();
            $this->settings->apimirror_xml = $this->getMirror('xml');
            $this->settings->apimirror_banner = $this->getMirror('banner');
            $this->settings->apimirror_zip = $this->getMirror('zip');
        } else {
            $mirrors = array(
                'xml' => array($this->settings->data['apimirror_xml']),
                'banner' => array($this->settings->data['apimirror_banner']),
                'zip'	=> array($this->settings->data['apimirror_zip'])
            );
        }

        $this->allMirrors = $mirrors;

        if ($andPick) {
            $this->pickMirror($mirrors);
        }

        return $mirrors;
    }

    public function setPreviousTime($time)
    {
        $this->settings->previoustime = $time;
        $this->previoustime = $time;

        return $this->previoustime;
    }

    public function getPreviousTime()
    {
        return $this->settings->previoustime;
    }
}